package br.com.mworks.controller;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.ufc.mworks.model.Categoria;
import br.ufc.mworks.model.Tarefa;

import com.example.mworks.R;
import com.example.mworks.TarefasActivity;

public class CustomAdapterCategoria extends BaseAdapter {

	// private final LayoutInflater inflater;
	// private final int resourceId;

	/*
	 * public CustomAdapter(Context context, int textViewResourceId,
	 * List<Categoria> objects) { super(context, textViewResourceId, objects);
	 * this.listaCategorias = objects; this.inflater =
	 * LayoutInflater.from(context); this.resourceId = textViewResourceId; }
	 */
	private ArrayList<Categoria> listaCategorias;
	Context c;

	public CustomAdapterCategoria(ArrayList<Categoria> listaCateg, Context context) {
		listaCategorias = listaCateg;
		c = context;
	}

	@Override
	public int getCount() {
		return listaCategorias.size();
	}

	@Override
	public Object getItem(int position) {
		return listaCategorias.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) c
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.item_listcategoria, null);
		}

		final ImageView imageCat = (ImageView) v.findViewById(R.id.imageCat);
		final TextView nomeCat = (TextView) v.findViewById(R.id.tituloCategoria);
		final TextView qtdTarefas = (TextView) v.findViewById(R.id.qtdTarefas);

		Categoria categoria = listaCategorias.get(position);

		nomeCat.setText(categoria.getNome());
		//qtdTarefas.setText(String.valueOf(categoria.getQtdTarefas()));

		v.setOnClickListener(new View.OnClickListener() {

			public void onClick(View arg0) {
				//c.startActivity(new Intent(c, TarefasActivity.class));
				Intent i = new Intent(c, TarefasActivity.class);
				i.putExtra("nomeCategoria", nomeCat.getText());
				i.putExtra("qtdeTarefas", qtdTarefas.getText());
				c.startActivity(i);
		    }
		});
		
		return v;

		/*
		 * final Categoria categoria = getItem(position);
		 * 
		 * convertView = inflater.inflate(resourceId, parent, false);
		 * 
		 * ImageView img = (ImageView) convertView.findViewById(R.id.image);
		 * TextView titCat = (TextView) convertView
		 * .findViewById(R.id.tituloCategoria); TextView qtdTar = (TextView)
		 * convertView.findViewById(R.id.qtdTarefas);
		 * 
		 * titCat.setText(categoria.getNome());
		 * qtdTar.setText(String.valueOf(categoria.getQtdTarefas()));
		 * 
		 * convertView.setOnClickListener(new OnClickListener() {
		 * 
		 * @Override public void onClick(View v) {
		 * 
		 * } });
		 * 
		 * return convertView;
		 */
	}
}
